package com.k12.user.controller;

import com.k12.user.model.entity.SysUserPost;
import com.k12.user.service.SysUserPostService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 用户与岗位关联表(SysUserPost)表控制层
 *
 * @author makejava
 * @since 2025-07-28 20:53:08
 */
@RestController
@RequestMapping("sysUserPost")
public class SysUserPostController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserPostService sysUserPostService;

    /**
     * 分页查询
     *
     * @param sysUserPost 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("getAllUserPost")
    public List<SysUserPost> queryByPage(SysUserPost sysUserPost) {
        return this.sysUserPostService.queryByPage(sysUserPost);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getOneUserPost/{id}")
    public SysUserPost queryById(@PathVariable("id") Long id) {
        return this.sysUserPostService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param sysUserPost 实体
     * @return 新增结果
     */
    @PostMapping("insertUserPost")
    public SysUserPost add(SysUserPost sysUserPost) {
        return this.sysUserPostService.insert(sysUserPost);
    }

    @PostMapping("addSysUserPost")
    public void addSysUserPost(List<SysUserPost> sysUserPost) {
        this.sysUserPostService.addSysUserPost(sysUserPost);
    }

    /**
     * 编辑数据
     *
     * @param sysUserPost 实体
     * @return 编辑结果
     */
    @PostMapping("updateUserPost")
    public SysUserPost edit(SysUserPost sysUserPost) {
        return this.sysUserPostService.update(sysUserPost);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deleteUserPost")
    public Boolean deleteById(Long id) {
        return this.sysUserPostService.deleteById(id);
    }

    @GetMapping("deleteUserPostByTenantId")
    public Boolean deleteUserPostByTenantId(Long id, String tenantId) {
        return this.sysUserPostService.deleteUserPostByTenantId(id,tenantId);
    }

    @GetMapping("getPostIds")
    public List<Long> getPostIds(@RequestParam("tenantId")String tenantId,@RequestParam("userId")Long userId) {
        return this.sysUserPostService.getPostIds(tenantId, userId);
    }


    @GetMapping("countUserPostById")
    public int countUserPostById(@RequestParam("postId")Long postId,@RequestParam("tenantId")String tenantId) {
        return this.sysUserPostService.countUserPostById(postId, tenantId);
    }

}

